
	jQuery(document).ready(function(){
		jQuery('.loginButton').click(function(){
			login();
		});
	});	

	var login = function(){
		if (validateLogin()) {
			jQuery.ajax({
				url: '../../login.do',
				data: { userName:jQuery('.inputUserName').val(), password:jQuery('.inputPassword').val() },
				type: 'POST',
				dataType: 'json',
				contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
				success: function(data) {
					
					if (data.sucess)
						location.href= "chat.jsp";
					else
						jQuery('.messageLogin').append('Access denied');
				}			
			});
		}
	};
	
	var validateLogin = function(){
		
		jQuery('.messageLogin').html('');
		
		var message = '';
		if (jQuery('.inputUserName').val() == '')
			message += 'UserName required. ';
		
		if (jQuery('.inputPassword').val() == '')
			message += 'Password required. ';
		
		if (message == '')
			return true;
		else {
			jQuery('.messageLogin').append(message);
			return false;
		}
	};